<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>app下载</title>
  <style>
    .masker {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 1002;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.4);
    }

    .c-mh24 {
      margin: 0 12px;
    }

    .c-p {
      position: relative;
    }

    .content {
      width: 90%;
      position: fixed;
      top: 20px;
      z-index: 1003;
      max-width: 640px;
      left: 50%;
      transform: translate(-50%);
      padding: 10px 12px;
      border-radius: 10px;
      background-color: #fff;
    }

    .content>div>img {
      width: 1.2rem;
      height: 2.2rem;
      position: absolute;
      top: 0.4rem;
      right: 0.3rem;
      z-index: 1004;
    }

    .imgbox {
      width: 1.6rem;
      height: 0.8rem;
      margin-left: 0.2rem;
      margin-right: 0.4rem;
    }

    .c-fs28 {
      font-size: 14px;
    }

    .c-fs22 {
      font-size: 12px;
    }

    .c-mt10 {
      margin-top: 5px;
    }

    .c-flex-row {
      display: flex;
      display: -webkit-flex;
      flex-direction: row;
      -webkit-flex-direction: row;
    }
  </style>
</head>

<body>
  <!-- <a id="downloadLink" download="资料下载" hidden class="download"></a> -->
  <div id="downNotice">
    <div class="masker"></div>
    <div class="c-mh24 c-p">
      <div class="content">
        <div class="">
          <img src="">
        </div>
        <p class="c-fs28">温馨提示</p>
        <p class="c-fs22 c-mt10 c-flex-row">点击右上角的
          <img src="" class="imgbox">选择在浏览器打开即可下载或打开App
        </p>
      </div>
    </div>
  </div>
  <script type="text/javascript">
    window.onload = function () {
      if (
        window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) !=
        "micromessenger"
      ) {
        document.getElementById('downNotice').style.display = 'none';
        openApp();
      } else {
        document.getElementById('downNotice').style.display = 'block';
      }
    }
    // 检查是否安装app
    function openApp(e) {
      var u = window.navigator.userAgent;
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      if(/MicroMessenger/gi.test(u)) {
        // 引导用户在浏览器中打开
          alert('请在浏览器中打开');
          return;
      }
      if (isAndroid) {
        android();
      }
      if (isiOS) {
        ios();
      }
    }

    function android() {
      var _clickTime = new Date().getTime();
      // window.location.href = 'alipays://platformapi/startapp?appId=20000123'; /***打开app的协议，有安卓同事提供***/
      window.location.href = 'ckjrflutter://lyyueapp/detail';
      //启动间隔20ms运行的定时器，并检测累计消耗时间是否超过3000ms，超过则结束
      var _count = 0,
        intHandle;
      intHandle = setInterval(function () {
        _count++;
        var elsTime = new Date().getTime() - _clickTime;
        if (_count >= 200 || elsTime > 5000) {
          console.log(_count)
          console.log(elsTime)
          clearInterval(intHandle);
          //检查app是否打开
          if (document.hidden || document.webkitHidden) {
            // 打开了
            window.close();
          } else {
            // 没打开
            // alert('没打开')
            window.location.href = "https://kpreport.ckjr001.com/studyAppDownload.html";//下载链接
          }
        }
      }, 20);

    }

    function ios() {
      var _clickTime = +(new Date());
      var ifr = document.createElement("iframe");
      ifr.src = "https://rscobj.ckjr001.com"; /***打开app的协议，有ios同事提供***/
      ifr.style.display = "none";
      document.body.appendChild(ifr);
      //启动间隔20ms运行的定时器，并检测累计消耗时间是否超过3000ms，超过则结束
      var _count = 0,
        intHandle;
      intHandle = setInterval(function () {
        _count++;
        var elsTime = +(new Date()) - _clickTime;
        console.log(_count, elsTime, +(new Date()), _clickTime)
        if (_count >= 200 || elsTime > 5000) {
          clearInterval(intHandle);
          document.body.removeChild(ifr);
          //检查app是否打开
          if (document.hidden || document.webkitHidden) {
            // 打开了
            window.close();
          } else {
            // 没打开
            // alert('没打开')
            window.location.href = "https://kpreport.ckjr001.com/studyAppDownload.html";//下载链接
          }
        }
      }, 20);
    }
    // var downUrl = window.location.href.split('?url=')[1];
    // window.location.href = 'http://qiniu3.51ckjr.com/FqTHBv8wvqPdKFnKettMk9QovSU-?attname=卖报歌.mp3&datumId=131&reload';
    // }
    // }
  </script>
  <!-- <div id="btn">
    <a onclick="openApp()"><button>打开app</button></a>
  </div> -->
</body>

</html>